﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HopNguyenCore;

namespace HopNguyenCms.Controllers
{
    public class SystemlogsController : Controller
    {
        private HopNguyenEntities db = new HopNguyenEntities();

        //
        // GET: /Systemlogs/

        public ActionResult Index()
        {
            var systemlogs = db.SystemLogs.Include(s => s.Admin);
            return View(systemlogs.ToList());
        }

        //
        // GET: /Systemlogs/Details/5

        public ActionResult Details(int id = 0)
        {
            SystemLog systemlog = db.SystemLogs.Find(id);
            if (systemlog == null)
            {
                return HttpNotFound();
            }
            return View(systemlog);
        }

        //
        // GET: /Systemlogs/Create

        public ActionResult Create()
        {
            ViewBag.AdminError = new SelectList(db.Admins, "Id", "Username");
            return View();
        }

        //
        // POST: /Systemlogs/Create

        [HttpPost]
        public ActionResult Create(SystemLog systemlog)
        {
            if (ModelState.IsValid)
            {
                db.SystemLogs.Add(systemlog);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.AdminError = new SelectList(db.Admins, "Id", "Username", systemlog.AdminError);
            return View(systemlog);
        }

        //
        // GET: /Systemlogs/Edit/5

        public ActionResult Edit(int id = 0)
        {
            SystemLog systemlog = db.SystemLogs.Find(id);
            if (systemlog == null)
            {
                return HttpNotFound();
            }
            ViewBag.AdminError = new SelectList(db.Admins, "Id", "Username", systemlog.AdminError);
            return View(systemlog);
        }

        //
        // POST: /Systemlogs/Edit/5

        [HttpPost]
        public ActionResult Edit(SystemLog systemlog)
        {
            if (ModelState.IsValid)
            {
                db.Entry(systemlog).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.AdminError = new SelectList(db.Admins, "Id", "Username", systemlog.AdminError);
            return View(systemlog);
        }

        //
        // GET: /Systemlogs/Delete/5

        public ActionResult Delete(int id = 0)
        {
            SystemLog systemlog = db.SystemLogs.Find(id);
            if (systemlog == null)
            {
                return HttpNotFound();
            }
            return View(systemlog);
        }

        //
        // POST: /Systemlogs/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            SystemLog systemlog = db.SystemLogs.Find(id);
            db.SystemLogs.Remove(systemlog);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}